package pl.edu.agh.uddiProxy.server;

import java.util.HashMap;
import java.util.Map;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

import pl.edu.agh.uddiProxy.client.Parameter;
import pl.edu.agh.uddiProxy.client.SearchService;
import pl.edu.agh.uddiProxy.types.ParameterType;
import pl.edu.agh.uddiProxy.types.ParametersMap;

public class SearchServiceImpl extends RemoteServiceServlet implements SearchService {

	private static final long serialVersionUID = -5808289517942745095L;

	public Map<String, Parameter> getParametersMap() {
		Map<String, Parameter> map = new HashMap<String, Parameter>();
		
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
				new String[] { "context.xml" });
		ParametersMap parametersMap = (ParametersMap) context.getBean("ParametersMap");
		for (String s : parametersMap.getParametersMap().keySet()) {
			ParameterType type = parametersMap.getParametersMap().get(s);
			Parameter parameter = new Parameter();
			parameter.setMaxValue(type.getMaxValue());
			parameter.setMinValue(type.getMinValue());
			parameter.setName(type.getName());
			parameter.setType(type.getType());
			parameter.setUnit(type.getUnit());
			map.put(s, parameter);
		}
		
		return map;
	}

}
